/* --------------------------------------------------------
 * Copyright (c) aeky , Inc.  All rights reserved.
 * --------------------------------------------------------
 */
package com.aeky.server.rpcservice;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.aeky.client.rpcservice.PrepareDataRPCService;
import com.aeky.domain.Menu;
import com.aeky.model.BaseMapData;
import com.aeky.server.service.IPrepareDataService;
import com.aeky.server.utils.RecordUtil;

/**
 * 
 * @author aeky
 */
@Service("prepareDataRpc")
public class PrepareDataRPCServiceImpl implements PrepareDataRPCService {

    @Autowired
    private IPrepareDataService prepareDataService;

    /*
     * 
     * @see com.aeky.client.rpcservice.PrepareDataService#prepareBasicData
     * (java.lang .Long)
     */
    @Override
    public BaseMapData prepareBasicData(String loginName) {
        BaseMapData d = new BaseMapData();
        d.put("menuNodeList", initTree(""));
        return d;
    }

    private List<Map<String, Object>> initTree(String loginName) {
        List<Map<String, Object>> menuNodeList = new ArrayList<Map<String, Object>>();
        List<Menu> menuList = prepareDataService.findMenuByLoginName(loginName);
        for (Menu menu : menuList) {
            Map<String, Object> menuNode = RecordUtil.createBaseModelData(menu, "");
            menuNodeList.add(menuNode);
        }
        return menuNodeList;
    }

}
